import { execSync } from "child_process";

export function pyDependsFromUrl(execPath: string, pkgname: string, sourceUrl: string, destPath: string) {
	const cmd = `${execPath} download ${pkgname} -i ${sourceUrl} -d ${destPath}`;
	try {
		execSync(cmd, { encoding: 'utf-8' }).toString().trim();
		console.log("download success" + pkgname);
		return true;
	}
	catch {
		console.log("download err catch" + pkgname);
		return false;
	}
}
// pyDepends("pylint","https://pypi.tuna.tsinghua.edu.cn/simple","/home/kylin/project/downdat/download/py/");

export function goDependsFromUrl(execPath: string, pkgUrl: string, destPath: string) {
	// go get -d github.com/go-sql-driver/mysql
	// logger.debug("goDependsFromUrl");
	// logger.debug(execPath);
	const cmd = `${execPath}  get   -d  ${pkgUrl}`;
	//go的三个环境变量做到配置文件里面
	// logger.debug(cmd);
	const envVar = { GOPATH: destPath, GO111MODULE: "on", GOPROXY: "https://goproxy.cn,direct", GOSUMDB: "off" }
	try {
		execSync(cmd, { encoding: 'utf-8', env: { ...process.env, ...envVar } }).toString().trim();
		console.log("download success" + pkgUrl);
		return true;
	}
	catch {
		console.log("download err catch" + pkgUrl);
		return false;
	}
}
// goDepends("golang.org/x/tools/gopls@v0.9.5","/home/kylin/project/downdat/download/go4")


